package com.zzh.zzhaiagent.exception;

import com.zzh.zzhaiagent.utils.ResultCodeEnum;
import lombok.Data;

/**
 * @author 张 志 豪
 * @version 1.0
 */
@Data
public class BusinessException extends RuntimeException{
    //异常状态码
    private Integer code;

    /**
     * 通过状态码和错误信息创建异常对象
     * @param message
     * @param code
     */
    public BusinessException(String message, Integer code){
        super(message);//调用RuntimeException来创建message
        this.code = code;
    }

    /**
     * 通过接收枚举类型来创建异常对象
     * @param resultCodeEnum
     */
    public BusinessException(ResultCodeEnum resultCodeEnum){
        super(resultCodeEnum.getMessage());//调用RuntimeException来创建message
        this.code = resultCodeEnum.getCode();
    }

    @Override
    public String toString() {
        return "zzhException{" +
                "code=" + code +
                ", message=" + this.getMessage() +
                '}';
    }

}
